﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.UI;

namespace TemplateFoundation.WebControls
{
    /// <summary>
    /// Provides extension methods for controls
    /// </summary>
    public static class Extensions
    {
        /// <summary>
        /// Renders a control to a string
        /// </summary>
        /// <param name="control"></param>
        /// <returns></returns>
        public static string RenderToString(this Control control)
        {
            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                using (var tw = new HtmlTextWriter(sw))
                {
                    control.RenderControl(tw);    
                }
            }
            return sb.ToString();
        }
    }
}
